<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><%= request.getParameter("id") != null ? "编辑成绩 - 学生信息管理系统" : "添加成绩 - 学生信息管理系统" %></title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar">
        <div class="container">
            <a href="index.jsp" class="navbar-brand">学生信息管理系统</a>
            <ul class="navbar-menu">
                <li><a href="index.jsp">首页</a></li>
                <li><a href="student-management.jsp">学生管理</a></li>
                <li><a href="class-management.jsp">班级管理</a></li>
                <li><a href="score-management.jsp">成绩管理</a></li>
                <li><a href="#" onclick="alert('退出登录'); return false;">退出登录</a></li>
            </ul>
        </div>
    </nav>
    
    <div class="container">
        <h1><%= request.getParameter("id") != null ? "编辑成绩信息" : "添加成绩信息" %></h1>
        
        <!-- 显示消息提示 -->
        <% if (request.getAttribute("message") != null) { %>
            <div class="message success">
                <%= request.getAttribute("message") %>
            </div>
        <% } %>
        
        <% if (request.getAttribute("error") != null) { %>
            <div class="message error">
                <%= request.getAttribute("error") %>
            </div>
        <% } %>
        
        <div class="form-container" style="max-width: 600px;">
            <div class="error-container" style="display: none;"></div>
            
            <form id="scoreForm" action="score" method="post" data-validate>
                <!-- 隐藏字段，用于区分添加和编辑操作 -->
                <input type="hidden" name="action" value="<%= request.getParameter("id") != null ? "update" : "insert" %>">
                <% if (request.getParameter("id") != null) { %>
                    <input type="hidden" name="scoreId" value="<%= request.getParameter("id") %>">
                <% } %>
                
                <div class="form-row" style="display: flex; gap: 20px; margin-bottom: 20px;">
                    <div class="form-group" style="flex: 1;">
                        <label for="studentId">学生 <span style="color: red;">*</span></label>
                        <select id="studentId" name="studentId" required>
                            <option value="">请选择学生</option>
                            <option value="202301001">张三 (202301001)</option>
                            <option value="202301002">李四 (202301002)</option>
                            <option value="202301003">王五 (202301003)</option>
                            <option value="202301004">赵六 (202301004)</option>
                            <option value="202301005">钱七 (202301005)</option>
                        </select>
                    </div>
                    
                    <div class="form-group" style="flex: 1;">
                        <label for="courseId">课程 <span style="color: red;">*</span></label>
                        <select id="courseId" name="courseId" required>
                            <option value="">请选择课程</option>
                            <option value="math">高等数学</option>
                            <option value="english">大学英语</option>
                            <option value="programming">程序设计基础</option>
                            <option value="database">数据库原理</option>
                            <option value="network">计算机网络</option>
                            <option value="os">操作系统</option>
                            <option value="ai">人工智能导论</option>
                            <option value="data-structure">数据结构</option>
                        </select>
                    </div>
                </div>
                
                <div class="form-row" style="display: flex; gap: 20px; margin-bottom: 20px;">
                    <div class="form-group" style="flex: 1;">
                        <label for="score">分数 <span style="color: red;">*</span></label>
                        <input type="number" id="score" name="score" min="0" max="100" step="0.1" required 
                               placeholder="请输入分数">
                    </div>
                    
                    <div class="form-group" style="flex: 1;">
                        <label for="grade">等级</label>
                        <input type="text" id="grade" name="grade" readonly 
                               style="background-color: #f0f0f0; cursor: not-allowed;">
                    </div>
                </div>
                
                <div class="form-row" style="display: flex; gap: 20px; margin-bottom: 20px;">
                    <div class="form-group" style="flex: 1;">
                        <label for="examDate">考试日期 <span style="color: red;">*</span></label>
                        <input type="date" id="examDate" name="examDate" required>
                    </div>
                    
                    <div class="form-group" style="flex: 1;">
                        <label for="examType">考试类型 <span style="color: red;">*</span></label>
                        <select id="examType" name="examType" required>
                            <option value="">请选择考试类型</option>
                            <option value="final">期末考试</option>
                            <option value="midterm">期中考试</option>
                            <option value="quiz">测验</option>
                            <option value="assignment">作业</option>
                            <option value="project">项目</option>
                        </select>
                    </div>
                </div>
                
                <div class="form-row" style="display: flex; gap: 20px; margin-bottom: 20px;">
                    <div class="form-group" style="flex: 1;">
                        <label for="weight">权重 (%)</label>
                        <input type="number" id="weight" name="weight" min="0" max="100" required value="100"
                               placeholder="请输入权重百分比">
                    </div>
                    
                    <div class="form-group" style="flex: 1;">
                        <label for="semester">学期 <span style="color: red;">*</span></label>
                        <select id="semester" name="semester" required>
                            <option value="">请选择学期</option>
                            <option value="2023-2024-1">2023-2024学年第一学期</option>
                            <option value="2023-2024-2">2023-2024学年第二学期</option>
                            <option value="2022-2023-1">2022-2023学年第一学期</option>
                            <option value="2022-2023-2">2022-2023学年第二学期</option>
                        </select>
                    </div>
                </div>
                
                <div class="form-group">
                    <label for="teacher">授课教师</label>
                    <input type="text" id="teacher" name="teacher" placeholder="请输入授课教师姓名">
                </div>
                
                <div class="form-group">
                    <label for="remark">备注</label>
                    <textarea id="remark" name="remark" rows="2" placeholder="请输入备注信息"></textarea>
                </div>
                
                <div class="form-group" style="margin-top: 30px;">
                    <button type="submit" class="btn btn-primary" style="margin-right: 10px;">保存</button>
                    <a href="score-management.jsp" class="btn btn-secondary">取消</a>
                </div>
            </form>
        </div>
    </div>
    
    <script src="js/script.js"></script>

</body>
</html>